package com.example.a14110100409.yuejiandemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.a14110100409.yuejiandemo.R;
import com.example.a14110100409.yuejiandemo.activity.ClubInfoActivity;
import com.example.a14110100409.yuejiandemo.fragment.ClubInfoFragment;
import com.example.a14110100409.yuejiandemo.javabean.Club;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by owner on 2017/9/25.
 */

public class ClubListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;

    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public ClubListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Club entity = (Club) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.club_name.setText(entity.getClub_name());
        String address="http://172.24.10.175/workout/Uploads/"+entity.getThumb();
        if(!entity.getThumb().equals("")){
            Picasso.with(mContext).load(address).into(viewHolder.club_thumb);
        }
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,ClubInfoActivity.class);
                intent.putExtra("club_id",entity.getId());
                intent.putExtra("club_name",entity.getClub_name());
                intent.putExtra("club_photo",entity.getThumb());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView club_thumb;
        TextView club_id,club_name;
        LinearLayout club_container;

        public ViewHolder(View itemView) {
            super(itemView);
            club_container = (LinearLayout) itemView.findViewById(R.id.club_container);
            club_name = (TextView) itemView.findViewById(R.id.club_name);
            club_thumb = (ImageView) itemView.findViewById(R.id.club_thumb);

        }
    }
}
